#include "lolevel.h"
#include "platform.h"
#include "core.h"
#include "../../leds.h"

static long *nrflag = (long*)0x8D14;

#include "../../../generic/capt_seq.c"

// sub_FF931550 -> sub_FF939E24
// Extracted method: (ff939e24-ff939e94)
void __attribute__((naked,noinline)) sub_FF939E24_my(long p) {
	asm volatile (
		"stmdb	sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, sl, lr} \n"
		"mov	r6, #0	\n" // ; 0x0
		"mov	r4, r0 \n"
		"BL	sub_FF93A94C \n"
		"mvn	r1, #0	\n" // ; 0x0
		"BL	sub_FF827C04 \n"
		"mov	r2, #4	\n" // ; 0x4
		"add	r1, sp, #8	\n" // ; 0x8
		"mov	r0, #138	\n" // ; 0x8a
		"BL	sub_FF86CD80 \n" // <PT_GetPropertyCaseString -839880>
		"tst	r0, #1	\n" // ; 0x1
		"movne	r1, #536	\n" // ; 0x218
		"ldrne	r0, =0xff939ff4 \n" // ; (61437353)  *"SsCaptureSeq.c"
		"BLNE	sub_FF81BDB8 \n" // <DebugAssert -1171616>
		"ldr	r8,  =0x00019b38 \n"
		"ldr	r5,  =0x00019a84 \n"
		"ldrsh	r1, [r8, #14] \n"
		"ldr	r0, [r5, #124] \n"
		"BL	sub_FF8F09B8 \n"
		"BL	sub_FF8451A4 \n"
		"ldr	r2,  =0x00008d18 \n"
		"add	r3, r4, #140	\n" // ; 0x8c
		"strh	r0, [r4, #136] \n"
		"strd	r2, [sp] \n"
		"mov	r1, r0 \n"
		"ldrh	r0, [r5, #84] \n"
		"ldrsh	r2, [r8, #12] \n"
		"ldr	r3,  =0x00008d14 \n"
		"BL	sub_FF93AE38 \n"
			"BL     capt_seq_hook_set_nr \n" // +
			"B		sub_FF939E98 \n" // + continue code in rom
 );
}

// sub_FF85C054 -> sub_FF86CF10
// Extracted method: (ff85e18c-ff85e248)
// Overridden calls:
// sub_FF931550 -> sub_FF939E24
// 1 add
void __attribute__((naked,noinline)) sub_FF85E18C_my() {
	asm volatile (
		"stmdb	sp!, {r4, r5, r6, lr} \n"
		"ldr	r4, [r0, #12] \n"
		"ldr	r6,  =0x00019a84 \n"
		"ldr	r0, [r4, #8] \n"
		"mov	r5, #0	\n" // ; 0x0
		"orr	r0, r0, #1	\n" // ; 0x1
		"str	r0, [r4, #8] \n"
		"ldr	r0, [r6, #36] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"moveq	r0, #2	\n" // ; 0x2
		"BLEQ	sub_FF8581D0 \n"
		"BL	sub_FF938748 \n"
		"ldr	r0, [r6, #36] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"BNE	loc_FF85E20C \n"
		"mov	r0, r4 \n"
		"BL	sub_FF938BDC \n"
		"tst	r0, #1	\n" // ; 0x1
		"movne	r2, r4 \n"
		"ldmneia	sp!, {r4, r5, r6, lr} \n"
		"movne	r1, #1	\n" // ; 0x1
		"BNE	sub_FF85C418 \n"
		"BL	sub_FF95B8EC \n"
		"BL	sub_FF86CF10 \n"
		"str	r0, [r4, #20] \n"
		"mov	r0, r4 \n"
		"BL	sub_FF939D3C \n"
		"BL	sub_FF93A7D4 \n"
		"mov	r0, r4 \n"
//	"BL	sub_FF939E24 \n"
	"BL	sub_FF939E24_my \n" // ------------------------>
			"BL     capt_seq_hook_raw_here\n"  // +
		"mov	r5, r0 \n"
		"B	loc_FF85E21C \n"
	"loc_FF85E20C:\n"
		"ldr	r0,  =0x000054b8 \n"
		"ldr	r0, [r0, #4] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"movne	r5, #29	\n" // ; 0x1d
	"loc_FF85E21C:\n"
		"BL	sub_FF93B7EC \n"
		"BL	sub_FF93B828 \n"
		"mov	r2, r4 \n"
		"mov	r1, #1	\n" // ; 0x1
		"mov	r0, r5 \n"
		"BL	sub_FF85C418 \n"
		"BL	sub_FF93A1F0 \n"
		"cmp	r0, #0	\n" // ; 0x0
		"ldrne	r0, [r4, #8] \n"
		"orrne	r0, r0, #8192	\n" // ; 0x2000
		"strne	r0, [r4, #8] \n"
		"ldmia	sp!, {r4, r5, r6, pc} \n"
 );
}

// Extracted method: (ff85de08-ff85e0a0)
// sub_FF85DE08
// Overridden calls:
// sub_FF85C054 -> sub_FF85E18C
// 1 added
void __attribute__((naked,noinline)) task_CaptSeqTask_my() {
	asm volatile (
		"stmdb	sp!, {r3, r4, r5, r6, r7, r8, r9, lr} \n"
		"ldr	r6,  =0x00019a84 \n"
		"ldr	r5,  =0x000054b8 \n"
		"mov	r9, #1	\n" // ; 0x1
		"mov	r7, #0	\n" // ; 0x0
	"loc_FF85DE1C:\n"
		"ldr	r0, [r5, #12] \n"
		"mov	r2, #0	\n" // ; 0x0
		"mov	r1, sp \n"
		"BL	sub_FF827E54 \n"
		"tst	r0, #1	\n" // ; 0x1
		"BEQ	loc_FF85DE48 \n"
		"ldr	r1,  =0x0000048e \n"
		"ldr	r0, =0xff85dae0 \n" // ; (68537353)  *"SsShootTask.c"
		"BL	sub_FF81BDB8 \n" // <DebugAssert -270468>
		"BL	sub_FF81BB70 \n" // <ExitTask -271056>
		"ldmia	sp!, {r3, r4, r5, r6, r7, r8, r9, pc} \n"
	"loc_FF85DE48:\n"
		"ldr	r0, [sp] \n"
		"ldr	r1, [r0] \n"
		"cmp	r1, #27	\n" // ; 0x1b
		"addls	pc, pc, r1, lsl #2 \n"
		"B	loc_FF85E068 \n"
		"B	loc_FF85DECC \n"
		"B	loc_FF85DF34 \n"
		"B	loc_FF85DF3C \n"
		"B	loc_FF85DF54 \n"
		"B	loc_FF85DF48 \n"
		"B	loc_FF85DF5C \n"
		"B	loc_FF85DF64 \n"
		"B	loc_FF85DF6C \n"
		"B	loc_FF85DFC4 \n"
		"B	loc_FF85DFD0 \n"
		"B	loc_FF85DFD8 \n"
		"B	loc_FF85DFE0 \n"
		"B	loc_FF85DFE8 \n"
		"B	loc_FF85DFF0 \n"
		"B	loc_FF85DFF8 \n"
		"B	loc_FF85E000 \n"
		"B	loc_FF85E008 \n"
		"B	loc_FF85E014 \n"
		"B	loc_FF85E01C \n"
		"B	loc_FF85E024 \n"
		"B	loc_FF85E02C \n"
		"B	loc_FF85E038 \n"
		"B	loc_FF85E040 \n"
		"B	loc_FF85E048 \n"
		"B	loc_FF85E050 \n"
		"B	loc_FF85E058 \n"
		"B	loc_FF85E060 \n"
		"B	loc_FF85E074 \n"

	"loc_FF85DECC:\n"
		"BL	sub_FF93876C \n"
                "BL     shooting_expo_param_override\n"  // +
		"BL	sub_FF85BFE8 \n"
		"ldr	r0, [r6, #36] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"BEQ	loc_FF85E074 \n"
		"BL	sub_FF85D7B0 \n"
		"mov	r4, r0 \n"
		"ldr	r0, [r6, #36] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"BEQ	loc_FF85DF14 \n"
		"mov	r0, #12	\n" // ; 0xc
		"BL	sub_FF860E24 \n"
		"tst	r0, #1	\n" // ; 0x1
		"strne	r9, [r5, #4] \n"
		"ldrne	r0, [r4, #8] \n"
		"orrne	r0, r0, #1073741824	\n" // ; 0x40000000
		"strne	r0, [r4, #8] \n"
		"BNE	loc_FF85E074 \n"
	"loc_FF85DF14:\n"
		"BL	sub_FF95B8EC \n"
		"BL	sub_FF86CF10 \n"
		"str	r0, [r4, #20] \n"
		"mov	r0, r4 \n"

//	"BL	sub_FF939E24 \n"
	"BL	sub_FF939E24_my \n"
			"BL     capt_seq_hook_raw_here\n"  // +

		"tst	r0, #1	\n" // ; 0x1
		"strne	r9, [r5, #4] \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DF34:\n"
//	"BL	sub_FF85E18C \n"
	"BL	sub_FF85E18C_my \n" // ------------------------>
		"B	loc_FF85DF4C \n"
	"loc_FF85DF3C:\n"
		"mov	r0, #1	\n" // ; 0x1
		"BL	sub_FF938914 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DF48:\n"
		"BL	sub_FF938404 \n"
	"loc_FF85DF4C:\n"
		"str	r7, [r6, #36] \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DF54:\n"
		"BL	sub_FF938738 \n"
		"B	loc_FF85DF4C \n"
	"loc_FF85DF5C:\n"
		"BL	sub_FF938740 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DF64:\n"
		"BL	sub_FF938834 \n"
		"B	loc_FF85DFC8 \n"
	"loc_FF85DF6C:\n"
		"ldr	r4, [r0, #12] \n"
		"BL	sub_FF938748 \n"
		"mov	r0, r4 \n"
		"BL	sub_FF938F5C \n"
		"tst	r0, #1	\n" // ; 0x1
		"mov	r8, r0 \n"
		"BNE	loc_FF85DFAC \n"
		"BL	sub_FF86CF10 \n"
		"str	r0, [r4, #20] \n"
		"mov	r0, r4 \n"
		"BL	sub_FF939D3C \n"
		"mov	r0, r4 \n"
		"BL	sub_FF93A250 \n"
		"mov	r8, r0 \n"
		"ldr	r0, [r4, #20] \n"
		"BL	sub_FF86D11C \n"
	"loc_FF85DFAC:\n"
		"BL	sub_FF938738 \n"
		"mov	r2, r4 \n"
		"mov	r1, #9	\n" // ; 0x9
		"mov	r0, r8 \n"
		"BL	sub_FF85C418 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFC4:\n"
		"BL	sub_FF938894 \n"
	"loc_FF85DFC8:\n"
		"BL	sub_FF85BFE8 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFD0:\n"
		"BL	sub_FF938738 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFD8:\n"
		"BL	sub_FF9391C8 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFE0:\n"
		"BL	sub_FF9393B0 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFE8:\n"
		"BL	sub_FF939440 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFF0:\n"
		"BL	sub_FF9394F4 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85DFF8:\n"
		"BL	sub_FF9396EC \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E000:\n"
		"BL	sub_FF93973C \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E008:\n"
		"mov	r0, #0	\n" // ; 0x0
		"BL	sub_FF9397C0 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E014:\n"
		"BL	sub_FF939910 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E01C:\n"
		"BL	sub_FF9399A4 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E024:\n"
		"BL	sub_FF939A6C \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E02C:\n"
		"BL	sub_FF938A38 \n"
		"BL	sub_FF824CFC \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E038:\n"
		"BL	sub_FF9395B0 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E040:\n"
		"BL	sub_FF93961C \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E048:\n"
		"BL	sub_FF93B7D0 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E050:\n"
		"BL	sub_FF93B7EC \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E058:\n"
		"BL	sub_FF93B7FC \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E060:\n"
		"BL	sub_FF93B828 \n"
		"B	loc_FF85E074 \n"
	"loc_FF85E068:\n"
		"ldr	r1,  =0x0000058e \n"
		"ldr	r0,  =0xff85dae0 \n"
		"BL	sub_FF81BDB8 \n" // <DebugAssert -271032>
	"loc_FF85E074:\n"
		"ldr	r0, [sp] \n"
		"ldr	r1, [r0, #4] \n"
		"ldr	r0, [r5, #8] \n"
		"BL	sub_FF827BD0 \n"
		"ldr	r4, [sp] \n"
		"ldr	r0, [r4, #8] \n"
		"cmp	r0, #0	\n" // ; 0x0
		"ldreq	r1,  =0x0000010d \n"
		"ldreq	r0,  =0xff85dae0 \n"
		"BLEQ	sub_FF81BDB8 \n" // <DebugAssert -271072>
		"str	r7, [r4, #8] \n"
		"B	loc_FF85DE1C \n"
    );
} //#fe


/*************************************************************/
void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "SUB     SP, SP, #0x20\n"
                 "LDR     R8, =0xBB8\n"
                 "LDR     R7, =0x6A34\n"
                 "LDR     R5, =0x3DBE4\n"
                 "MOV     R0, #0\n"
                 "ADD     R6, SP, #0x10\n"
                 "STR     R0, [SP,#0xC]\n"
 "loc_FF8B3D88:\n"
                 "LDR     R0, [R7,#0x20]\n"
                 "MOV     R2, #0\n"
                 "ADD     R1, SP, #0x1C\n"
                 "BL      sub_FF827E54\n"
                 "LDR     R0, [SP,#0xC]\n"
                 "CMP     R0, #1\n"
                 "BNE     loc_FF8B3DD0\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0x13\n"
                 "CMPNE   R0, #0x14\n"
                 "CMPNE   R0, #0x15\n"
                 "BEQ     loc_FF8B3EEC\n"
                 "CMP     R0, #0x27\n"
                 "BEQ     loc_FF8B3EC4\n"
                 "ADD     R1, SP, #0xC\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8B3D18\n"
 "loc_FF8B3DD0:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x2C\n"
                 "BNE     loc_FF8B3E00\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8B4FD4\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF827BD0\n"
                 "BL      sub_FF81BB70\n"
                 "ADD     SP, SP, #0x20\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 "loc_FF8B3E00:\n"
                 "CMP     R1, #0x2B\n"
                 "BNE     loc_FF8B3E1C\n"
                 "LDR     R2, [R0,#0x88]!\n"
                 "LDR     R1, [R0,#4]\n"
                 "MOV     R0, R1\n"
                 "BLX     R2\n"
                 "B       loc_FF8B4354\n"
 "loc_FF8B3E1C:\n"
                 "CMP     R1, #0x25\n"
                 "BNE     loc_FF8B3E6C\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF827C04\n"
                 "LDR     R0, =0xFF8B07A0\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF92C11C\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x80\n"
                 "BL      sub_FF827B08\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0xD1B\n"
                 "BNE     loc_FF8B3EB0\n"
 "loc_FF8B3E58:\n"
                 "LDR     R1, [SP,#0x1C]\n"
                 "LDR     R0, [R1,#0x8C]\n"
                 "LDR     R1, [R1,#0x88]\n"
                 "BLX     R1\n"
                 "B       loc_FF8B4354\n"
 "loc_FF8B3E6C:\n"
                 "CMP     R1, #0x26\n"
                 "BNE     loc_FF8B3EBC\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8B3D18\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF827C04\n"
                 "LDR     R0, =0xFF8B07B0\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF92C3A4\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R8\n"
                 "MOV     R1, #0x100\n"
                 "BL      sub_FF827B08\n"
                 "TST     R0, #1\n"
                 "BEQ     loc_FF8B3E58\n"
                 "LDR     R1, =0xD25\n"
 "loc_FF8B3EB0:\n"
                 "LDR     R0, =0xFF8B0EA0\n"
                 "BL      sub_FF81BDB8\n"
                 "B       loc_FF8B3E58\n"
 "loc_FF8B3EBC:\n"
                 "CMP     R1, #0x27\n"
                 "BNE     loc_FF8B3ED4\n"
 "loc_FF8B3EC4:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "ADD     R1, SP, #0xC\n"
                 "BL      sub_FF8B3D18\n"
                 "B       loc_FF8B3E58\n"
 "loc_FF8B3ED4:\n"
                 "CMP     R1, #0x2A\n"
                 "BNE     loc_FF8B3EEC\n"
                 "BL      sub_FF893AAC\n"
                 "BL      sub_FF894878\n"
                 "BL      sub_FF8942FC\n"
                 "B       loc_FF8B3E58\n"
 "loc_FF8B3EEC:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R4, #1\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x11\n"
                 "CMPNE   R1, #0x12\n"
                 "BNE     loc_FF8B3F5C\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8B282C\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8B53A8\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x90]\n"
                 "LDR     R2, [R0,#0x94]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "B       loc_FF8B4294\n"
 "loc_FF8B3F5C:\n"
                 "CMP     R1, #0x13\n"
                 "CMPNE   R1, #0x14\n"
                 "CMPNE   R1, #0x15\n"
                 "BNE     loc_FF8B4010\n"
                 "ADD     R3, SP, #0xC\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8B2A74\n"
                 "CMP     R0, #1\n"
                 "MOV     R4, R0\n"
                 "CMPNE   R4, #5\n"
                 "BNE     loc_FF8B3FAC\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "LDR     R1, [R0,#0x7C]!\n"
                 "LDR     R12, [R0,#0xC]!\n"
                 "LDR     R3, [R0,#4]\n"
                 "MOV     R0, SP\n"
                 "BLX     R12\n"
                 "B       loc_FF8B3FE4\n"
 "loc_FF8B3FAC:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "CMP     R4, #2\n"
                 "LDR     R3, [R0,#0x8C]\n"
                 "CMPNE   R4, #6\n"
                 "BNE     loc_FF8B3FF8\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "MOV     R0, SP\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #1\n"
                 "BLX     R12\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, SP\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FF8B3A2C\n"
 "loc_FF8B3FE4:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R2, [SP,#0xC]\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FF8B3CB8\n"
                 "B       loc_FF8B4294\n"
 "loc_FF8B3FF8:\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R12, [R0,#0x88]\n"
                 "ADD     R0, R0, #4\n"
                 "MOV     R2, R4\n"
                 "BLX     R12\n"
                 "B       loc_FF8B4294\n"
 "loc_FF8B4010:\n"
                 "CMP     R1, #0x21\n"
                 "CMPNE   R1, #0x22\n"
                 "BNE     loc_FF8B405C\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R1, R0, R1,LSL#2\n"
                 "SUB     R1, R1, #8\n"
                 "LDMIA   R1, {R2-R4}\n"
                 "STMIA   R6, {R2-R4}\n"
                 "BL      sub_FF8B1DB8\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8B20A8\n"
                 "B       loc_FF8B4294\n"
 "loc_FF8B405C:\n"
                 "ADD     R1, R0, #4\n"
                 "LDMIA   R1, {R2,R3,R12}\n"
                 "STMIA   R6, {R2,R3,R12}\n"
                 "LDR     R1, [R0]\n"
                 "CMP     R1, #0x24\n"
                 "ADDLS   PC, PC, R1,LSL#2\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4078:\n"
                 "B       loc_FF8B410C\n"
 "loc_FF8B407C:\n"
                 "B       loc_FF8B410C\n"
 "loc_FF8B4080:\n"
                 "B       loc_FF8B415C\n"
 "loc_FF8B4084:\n"
                 "B       loc_FF8B4164\n"
 "loc_FF8B4088:\n"
                 "B       loc_FF8B4164\n"
 "loc_FF8B408C:\n"
                 "B       loc_FF8B4164\n"
 "loc_FF8B4090:\n"
                 "B       loc_FF8B410C\n"
 "loc_FF8B4094:\n"
                 "B       loc_FF8B415C\n"
 "loc_FF8B4098:\n"
                 "B       loc_FF8B4164\n"
 "loc_FF8B409C:\n"
                 "B       loc_FF8B4164\n"
 "loc_FF8B40A0:\n"
                 "B       loc_FF8B417C\n"
 "loc_FF8B40A4:\n"
                 "B       loc_FF8B417C\n"
 "loc_FF8B40A8:\n"
                 "B       loc_FF8B4268\n"
 "loc_FF8B40AC:\n"
                 "B       loc_FF8B4270\n"
 "loc_FF8B40B0:\n"
                 "B       loc_FF8B4270\n"
 "loc_FF8B40B4:\n"
                 "B       loc_FF8B4270\n"
 "loc_FF8B40B8:\n"
                 "B       loc_FF8B4270\n"
 "loc_FF8B40BC:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B40C0:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B40C4:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B40C8:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B40CC:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B40D0:\n"
                 "B       loc_FF8B416C\n"
 "loc_FF8B40D4:\n"
                 "B       loc_FF8B4174\n"
 "loc_FF8B40D8:\n"
                 "B       loc_FF8B4174\n"
 "loc_FF8B40DC:\n"
                 "B       loc_FF8B4188\n"
 "loc_FF8B40E0:\n"
                 "B       loc_FF8B4188\n"
 "loc_FF8B40E4:\n"
                 "B       loc_FF8B4190\n"
 "loc_FF8B40E8:\n"
                 "B       loc_FF8B41C0\n"
 "loc_FF8B40EC:\n"
                 "B       loc_FF8B41F0\n"
 "loc_FF8B40F0:\n"
                 "B       loc_FF8B4220\n"
 "loc_FF8B40F4:\n"
                 "B       loc_FF8B4250\n"
 "loc_FF8B40F8:\n"
                 "B       loc_FF8B4250\n"
 "loc_FF8B40FC:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4100:\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4104:\n"
                 "B       loc_FF8B4258\n"
 "loc_FF8B4108:\n"
                 "B       loc_FF8B4260\n"
 "loc_FF8B410C:\n"
                 "BL      sub_FF8B0C88\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B415C:\n"
                 "BL      sub_FF8B0F18\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4164:\n"
                 "BL      sub_FF8B111C\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B416C:\n"
                 "BL      sub_FF8B1384\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4174:\n"
                 "BL      sub_FF8B1578\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B417C:\n"
                 "BL      sub_FF8B17E0_my\n"   //-------------->
                 "MOV     R4, #0\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4188:\n"
                 "BL      sub_FF8B191C\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4190:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8B5048\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B41C0:\n"
                 "LDRH    R1, [R0,#4]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8B51C4\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B41F0:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R0,#6]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R5,#8]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8B5270\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4220:\n"
                 "LDRH    R1, [R5]\n"
                 "STRH    R1, [SP,#0x10]\n"
                 "LDRH    R1, [R5,#2]\n"
                 "STRH    R1, [SP,#0x12]\n"
                 "LDRH    R1, [R5,#4]\n"
                 "STRH    R1, [SP,#0x14]\n"
                 "LDRH    R1, [R5,#6]\n"
                 "STRH    R1, [SP,#0x16]\n"
                 "LDRH    R1, [R0,#0xC]\n"
                 "STRH    R1, [SP,#0x18]\n"
                 "BL      sub_FF8B5310\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4250:\n"
                 "BL      sub_FF8B1B90\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4258:\n"
                 "BL      sub_FF8B21AC\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4260:\n"
                 "BL      sub_FF8B23E4\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4268:\n"
                 "BL      sub_FF8B255C\n"
                 "B       loc_FF8B4274\n"
 "loc_FF8B4270:\n"
                 "BL      sub_FF8B26F4\n"
 "loc_FF8B4274:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "LDR     R3, [R0,#0x88]\n"
                 "LDR     R2, [R0,#0x8C]\n"
                 "ADD     R0, R0, #4\n"
                 "BLX     R3\n"
                 "CMP     R4, #1\n"
                 "BNE     loc_FF8B42DC\n"
 "loc_FF8B4294:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "MOV     R2, #0xC\n"
                 "LDR     R1, [R0,#0x7C]\n"
                 "ADD     R1, R1, R1,LSL#1\n"
                 "ADD     R0, R0, R1,LSL#2\n"
                 "SUB     R4, R0, #8\n"
                 "LDR     R0, =0x3DBE4\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFAA4B2C\n"
                 "LDR     R0, =0x3DBF0\n"
                 "MOV     R2, #0xC\n"
                 "ADD     R1, SP, #0x10\n"
                 "BL      sub_FFAA4B2C\n"
                 "LDR     R0, =0x3DBFC\n"
                 "MOV     R2, #0xC\n"
                 "MOV     R1, R4\n"
                 "BL      sub_FFAA4B2C\n"
                 "B       loc_FF8B4354\n"
 "loc_FF8B42DC:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "LDR     R0, [R0]\n"
                 "CMP     R0, #0xB\n"
                 "BNE     loc_FF8B4324\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "BL      sub_FF8B0A90\n"
                 "MOV     R3, #0\n"
                 "STR     R3, [SP]\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #0\n"
                 "B       loc_FF8B4350\n"
 "loc_FF8B4324:\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
                 "BL      sub_FF8B0A90\n"
                 "MOV     R3, #1\n"
                 "MOV     R2, #1\n"
                 "MOV     R1, #1\n"
                 "MOV     R0, #1\n"
                 "STR     R3, [SP]\n"
 "loc_FF8B4350:\n"
                 "BL      sub_FF8B0BD0\n"
 "loc_FF8B4354:\n"
                 "LDR     R0, [SP,#0x1C]\n"
                 "BL      sub_FF8B4FD4\n"
                 "B       loc_FF8B3D88\n"
 );
}

void __attribute__((naked,noinline)) sub_FF8B17E0_my(){
 asm volatile(
                 "STMFD   SP!, {R4-R8,LR}\n"
                 "LDR     R7, =0x6A34\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R1, #0x3E\n"
                 "BL      sub_FF827C04\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "MOV     R2, #0\n"
                 "MOV     R1, #0\n"
                 "BL      sub_FF8B0824\n"
                 "MOV     R6, R0\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF8B0930\n"
                 "LDRSH   R0, [R4,#8]\n"
                 "BL      sub_FF8B0988\n"
                 "LDRSH   R0, [R4,#0xA]\n"
                 "BL      sub_FF8B09E0\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "BL      sub_FF8B0A38\n"
                 "MOV     R5, R0\n"
                 "LDR     R0, [R4]\n"
                 "LDR     R8, =0x3DBFC\n"
                 "CMP     R0, #0xB\n"
                 "MOVEQ   R6, #0\n"
                 "MOVEQ   R5, #0\n"
                 "BEQ     loc_FF8B1870\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8B1870\n"
                 "LDRSH   R0, [R4,#4]\n"
                 "LDR     R1, =0xFF8B0790\n"
                 "MOV     R2, #2\n"
                 "BL      sub_FF92C270\n"
                 "STRH    R0, [R4,#4]\n"
                 "MOV     R0, #0\n"
                 "STR     R0, [R7,#0x28]\n"
                 "B       loc_FF8B1878\n"
 "loc_FF8B1870:\n"
                 "LDRH    R0, [R8]\n"
                 "STRH    R0, [R4,#4]\n"
 "loc_FF8B1878:\n"
                 "CMP     R5, #1\n"
                 "LDRNEH  R0, [R8,#8]\n"
                 "BNE     loc_FF8B1894\n"
                 "LDRSH   R0, [R4,#0xC]\n"
                 "MOV     R2, #0x20\n"
                 "LDR     R1, =0xFF8B0814\n"
                 "BL      sub_FF8B5004\n"
 "loc_FF8B1894:\n"
                 "STRH    R0, [R4,#0xC]\n"
                 "LDRSH   R0, [R4,#6]\n"
                 "BL      sub_FF8937F8_my\n" //---------->
                 "LDRSH   R0, [R4,#8]\n"
                 "MOV     R1, #1\n"
                 "BL      sub_FF893FF4\n"
                 "MOV     R1, #0\n"
                 "ADD     R0, R4, #8\n"
                 "BL      sub_FF89407C\n"
                 "LDRSH   R0, [R4,#0xE]\n"
                 "BL      sub_FF8A774C\n"
                 "LDR     R4, =0xBB8\n"
                 "CMP     R6, #1\n"
                 "BNE     loc_FF8B18EC\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #2\n"
                 "BL      sub_FF827B08\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x532\n"
                 "LDRNE   R0, =0xFF8B0EA0\n"
                 "BLNE    sub_FF81BDB8\n"
 "loc_FF8B18EC:\n"
                 "CMP     R5, #1\n"
                 "LDMNEFD SP!, {R4-R8,PC}\n"
                 "LDR     R0, [R7,#0x1C]\n"
                 "MOV     R2, R4\n"
                 "MOV     R1, #0x20\n"
                 "BL      sub_FF827B08\n"
                 "TST     R0, #1\n"
                 "LDRNE   R1, =0x537\n"
                 "LDRNE   R0, =0xFF8B0EA0\n"
                 "LDMNEFD SP!, {R4-R8,LR}\n"
                 "BNE     sub_FF81BDB8\n"
                 "LDMFD   SP!, {R4-R8,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF8937F8_my(){
 asm volatile(
                 "STMFD   SP!, {R4-R6,LR}\n"
                 "LDR     R5, =0x650C\n"
                 "MOV     R4, R0\n"
                 "LDR     R0, [R5,#4]\n"
                 "CMP     R0, #1\n"
                 "LDRNE   R1, =0x16D\n"
                 "LDRNE   R0, =0xFF893590\n"
                 "BLNE    sub_FF81BDB8\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQSH R4, [R5,#2]\n"
                 "CMN     R4, #0xC00\n"
                 "LDREQ   R1, =0x173\n"
                 "LDREQ   R0, =0xFF893590\n"
                 "STRH    R4, [R5,#2]\n"
                 "BLEQ    sub_FF81BDB8\n"
                 "MOV     R0, R4\n"
                 "BL      apex2us\n"     // *
                 "MOV     R4, R0\n"
           //    "BL      nullsub_216\n"
                 "MOV     R0, R4\n"
                 "BL      sub_FF8C6D10\n"
                 "TST     R0, #1\n"
                 "LDMNEFD SP!, {R4-R6,LR}\n"
                 "MOVNE   R1, #0x178\n"
                 "LDRNE   R0, =0xFF893590\n"
                 "BNE     sub_FF81BDB8\n"
                 "LDMFD   SP!, {R4-R6,PC}\n"
 );
}
